package krow.dev.contest.view;

import java.util.ArrayList;
import java.util.List;

import krow.dev.contest.R;
import krow.dev.contest.model.TabItem;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class MenuListAdapter extends BaseAdapter {

	private List<TabItem> mMenuItemList;

	private LayoutInflater mLayoutInflater;
	
	public MenuListAdapter(Context context) {
	
		mMenuItemList = new ArrayList<TabItem>();
		
		mLayoutInflater = LayoutInflater.from(context);
	}

	public void setMenuItemList(List<TabItem> menuItemList){
		
		mMenuItemList.clear();
		mMenuItemList.addAll(menuItemList);
	}
	
	@Override
	public int getCount() {

		return mMenuItemList.size();
	}

	@Override
	public Object getItem(int position) {

		return mMenuItemList.get(position);
	}

	@Override
	public long getItemId(int position) {

		return position;
	}

	
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		TabItem menuItem = mMenuItemList.get(position);
		
		View view = mLayoutInflater.inflate(R.layout.item_menu, null);
		view.setTag(menuItem);
		
		View iconView = view.findViewById(R.id.view_icon);
		
		TextView nameView = (TextView) view.findViewById(R.id.text_name);
		nameView.setText(menuItem.getName());
		
		//TextView countView = (TextView) view.findViewById(R.id.text_count);
		//countView.setText(String.valueOf(menuItem.getCount2()));
		
		return view;
	}	
	
}
